﻿<%@ Page Language="C#" MasterPageFile="~/user.master" AutoEventWireup="true" Inherits="MediaMonitor.Users.Invoice"
    Theme="default" Title="Invoice" CodeBehind="invoice.aspx.cs" %>


<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script src="../rad-scripts/rad.js" type="text/javascript"></script>
        <script type="text/javascript">

            function getOuterHTML(object) {
                var element;
                if (!object) return null;
                element = document.createElement("div");
                element.appendChild(object.cloneNode(true));
                return element.innerHTML;
            }

            function PrintRadGrid() {
                var previewWnd = window.open('about:blank', '', '', false);
                var sh = '<%= ClientScript.GetWebResourceUrl(radGrid.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",radGrid.Skin)) %>';
                var styleStr = "<html><head><title>Media Monitor - Invoice</title><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
                var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= radGrid.ClientID %>').get_element()) + "</body></html>";
                previewWnd.document.open();
                previewWnd.document.write(htmlcontent);
                previewWnd.document.close();
                previewWnd.print();
                previewWnd.close();
            }


            function requestStart(sender, args) {
                if (args.get_eventTarget().indexOf("DownloadPDF") > 0)
                    args.set_enableAjax(false);
            }
        </script>
    </telerik:RadCodeBlock>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" Runat="Server">
<center> 
        <div style="padding-bottom: 5px;">
            <a href="javascript:void();" onclick="PrintRadGrid(); return false;"><b style="color: #336699; font-size:16px;">
                [ Print Invoice ]</b></a>
        </div>
        <telerik:RadGrid ID="radGrid" DataSourceID="sqlDSOrd" runat="server" AllowFilteringByColumn="False"
            AllowPaging="True" AllowSorting="True" GridLines="None" Skin="Hay" AutoGenerateColumns="false"
            GroupingSettings-CaseSensitive="false" OnPreRender="radGrid_PreRender" PageSize="20"
            ShowHeader="false" ShowFooter="false" Width="700">
            <MasterTableView DataKeyNames="OrderID" ShowFooter="true" ExpandCollapseColumn-Visible="false" >
                <Columns>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                        
                        <img src="../images/invoice-header.jpg" />

                        <table cellpadding="5" cellspacing="10"  style="border:none;">
                            <tr>
                                <td colspan="2" style="border:none;">
                                   
                                </td>
                            </tr>
                            <tr>
                                <td style="border: none;"><b>Order #:</b></td>
                                <td style="border: none;">
                                    <%#Eval("OrderID")%>
                                </td>
                                <td style="width:50px;"></td>
                                <td align="right" style="border: none;">
                                    <b>Date:</b>
                                </td>
                                <td style="border: none;">
                                    <%#Eval("DateAdded")%>
                                </td>
                            </tr>
                            <tr>
                                <td style="border: none;">
                                    <b>Customer:</b>
                                </td>
                                <td style="border: none;">
                                    <%#Eval("Fullname")%>
                                </td>
                                <td style="width: 50px;">
                                </td>
                                <td align="right" style="border: none;">
                                    <b>Email:</b>
                                </td>
                                <td style="border: none;">
                                    <%#Eval("Email")%>
                                </td>
                            </tr>
                            <tr>
                                <td style="border: none;">
                                    <b>Order Total:</b>
                                </td>
                                <td style="border: none;">
                                    <%# String.Format("{0:C2}", Eval("OrderTotal"))%>
                                </td>
                                <td colspan="3" style="width: 50px; border:none">
                                </td> 
                            </tr>
                        </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    </Columns>
                    
                <DetailTables>
                    <telerik:GridTableView AutoGenerateColumns="false" Caption="" AllowSorting="true"
                        PageSize="20" DataSourceID="sqlDSOrdDetail" AllowFilteringByColumn="false" ShowFooter="true" ExpandCollapseColumn-Display="false" ExpandCollapseColumn-Groupable="true" ShowHeader="true"
                        ItemStyle-VerticalAlign="Top" GroupsDefaultExpanded="true" >
                        <ParentTableRelation>
                            <telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID"  />
                        </ParentTableRelation>
                        <ItemStyle />
                        <AlternatingItemStyle />
                        <Columns >
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <%#Container.ItemIndex+1%>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn  DataField="ProductCode" HeaderText="Product Code"
                                ItemStyle-Width="70" />
                            <telerik:GridBoundColumn  DataField="ProductName" HeaderText="Product"
                                ItemStyle-Width="150" />
                            <telerik:GridBoundColumn  DataField="ProdVersionCode"
                                HeaderText="Version Code" ItemStyle-Width="70" />
                            <telerik:GridBoundColumn  DataField="ProdVersionName"
                                HeaderText="Version" ItemStyle-Width="150" />
                             
                            <telerik:GridBoundColumn DataField="Price" HeaderText="Price" ItemStyle-HorizontalAlign="Right"
                                DataFormatString="{0:C2}" Aggregate="Sum" FooterAggregateFormatString="Total: {0:c2}"
                                FooterStyle-HorizontalAlign="Right" FooterStyle-Font-Bold="true" />
                           
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>  
        </telerik:RadGrid>
  
        <br /><br />
    <div style="padding-bottom: 5px;">
        <a href="javascript:void();" onclick="PrintRadGrid(); return false;"><b style="color: #336699;
            font-size: 16px;">[ Print Invoice ]</b></a>
    </div>
</center>


    

    <asp:SqlDataSource ID="sqlDSOrd" runat="server" ConnectionString="<%$ConnectionStrings:DBAdex%>"
    SelectCommand="SELECT * FROM VOrder WHERE OrderID = @OrderID">
    <SelectParameters>
        <asp:QueryStringParameter Name="OrderID" QueryStringField="oid" DefaultValue="0" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

    <asp:SqlDataSource ID="sqlDSOrdDetail" runat="server" ConnectionString="<%$ConnectionStrings:DBAdex%>"
        SelectCommand="SELECT * FROM OrderDetail WHERE OrderID = @OrderID">
        <SelectParameters>
            <asp:QueryStringParameter Name="OrderID" QueryStringField="oid" DefaultValue="0"
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

